From 6abca78af4d695d0aaabad15acdfcbbe0cfab691 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marvin=20L=C3=B6bel?= Date: Wed, 28 Oct 2015 10:17:32 +0100 Subject: [PATCH] Made cwd setting in process builder optional --- src/cargo/ops/cargo_rustc/context.rs | 2 +- src/cargo/ops/cargo_rustc/engine.rs | 18 +++++++++++------- src/cargo/util/process_builder.rs | 23 +++++++++++++---------- src/cargo/util/rustc.rs | 4 ++-- src/cargo/util/vcs.rs | 4 ++-- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index caf5301d0..086d2782a 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -100,7 +100,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { /// specified as well as the exe suffix fn filename_parts(target: Option<&str>, cfg: &Config) -> CargoResult<(Option<(String, String)>, String)> { - let mut process = try!(util::process(cfg.rustc(), cfg.cwd())); + let mut process = util::process(cfg.rustc()); process.arg("-") .arg("--crate-name").arg("_") .arg("--crate-type").arg("dylib") diff --git a/src/cargo/ops/cargo_rustc/engine.rs b/src/cargo/ops/cargo_rustc/engine.rs index 2ce002962..9b5a31943 100644 --- a/src/cargo/ops/cargo_rustc/engine.rs +++ b/src/cargo/ops/cargo_rustc/engine.rs @@ -39,12 +39,16 @@ impl CommandPrototype { pub fn new(ty: CommandType, config: &Config) -> CargoResult { Ok(CommandPrototype { - builder: try!(match ty { - CommandType::Rustc => process(config.rustc(), config.cwd()), - CommandType::Rustdoc => process(config.rustdoc(), config.cwd()), - CommandType::Target(ref s) | - CommandType::Host(ref s) => process(s, config.cwd()), - }), + builder: { + let mut p = match ty { + CommandType::Rustc => process(config.rustc()), + CommandType::Rustdoc => process(config.rustdoc()), + CommandType::Target(ref s) | + CommandType::Host(ref s) => process(s), + }; + p.cwd(config.cwd()); + p + }, ty: ty, }) } @@ -73,7 +77,7 @@ impl CommandPrototype { } pub fn get_args(&self) -> &[OsString] { self.builder.get_args() } - pub fn get_cwd(&self) -> &Path { self.builder.get_cwd() } + pub fn get_cwd(&self) -> Option<&Path> { self.builder.get_cwd() } pub fn get_env(&self, var: &str) -> Option { self.builder.get_env(var) diff --git a/src/cargo/util/process_builder.rs b/src/cargo/util/process_builder.rs index 08003de69..d86df727f 100644 --- a/src/cargo/util/process_builder.rs +++ b/src/cargo/util/process_builder.rs @@ -5,7 +5,7 @@ use std::fmt; use std::path::Path; use std::process::{Command, Output}; -use util::{CargoResult, ProcessError, process_error}; +use util::{ProcessError, process_error}; use util::shell_escape::escape; #[derive(Clone, PartialEq, Debug)] @@ -13,7 +13,7 @@ pub struct ProcessBuilder { program: OsString, args: Vec, env: HashMap>, - cwd: OsString, + cwd: Option, } impl fmt::Display for ProcessBuilder { @@ -42,7 +42,7 @@ impl ProcessBuilder { } pub fn cwd>(&mut self, path: T) -> &mut ProcessBuilder { - self.cwd = path.as_ref().to_os_string(); + self.cwd = Some(path.as_ref().to_os_string()); self } @@ -60,8 +60,9 @@ impl ProcessBuilder { pub fn get_args(&self) -> &[OsString] { &self.args } - pub fn get_cwd(&self) -> &Path { - Path::new(&self.cwd) + + pub fn get_cwd(&self) -> Option<&Path> { + self.cwd.as_ref().map(Path::new) } pub fn get_env(&self, var: &str) -> Option { @@ -108,7 +109,9 @@ impl ProcessBuilder { pub fn build_command(&self) -> Command { let mut command = Command::new(&self.program); - command.current_dir(&self.get_cwd()); + if let Some(cwd) = self.get_cwd() { + command.current_dir(cwd); + } for arg in self.args.iter() { command.arg(arg); } @@ -131,11 +134,11 @@ impl ProcessBuilder { } } -pub fn process, U: AsRef>(cmd: T, cwd: U) -> CargoResult { - Ok(ProcessBuilder { +pub fn process>(cmd: T) -> ProcessBuilder { + ProcessBuilder { program: cmd.as_ref().to_os_string(), args: Vec::new(), - cwd: cwd.as_ref().to_os_string(), + cwd: None, env: HashMap::new(), - }) + } } diff --git a/src/cargo/util/rustc.rs b/src/cargo/util/rustc.rs index a0cb1720f..1ddc36db0 100644 --- a/src/cargo/util/rustc.rs +++ b/src/cargo/util/rustc.rs @@ -15,8 +15,8 @@ impl Rustc { /// If successful this function returns a description of the compiler along /// with a list of its capabilities. pub fn new>(path: P, cwd: &Path) -> CargoResult { - let mut cmd = try!(util::process(path.as_ref(), cwd)); - cmd.arg("-vV"); + let mut cmd = util::process(path.as_ref()); + cmd.cwd(cwd).arg("-vV"); let mut ret = Rustc::blank(); let mut first = cmd.clone(); diff --git a/src/cargo/util/vcs.rs b/src/cargo/util/vcs.rs index cad07c53b..16fc72333 100644 --- a/src/cargo/util/vcs.rs +++ b/src/cargo/util/vcs.rs @@ -19,11 +19,11 @@ impl GitRepo { impl HgRepo { pub fn init(path: &Path, cwd: &Path) -> CargoResult { - try!(try!(process("hg", cwd)).arg("init").arg(path).exec()); + try!(process("hg").cwd(cwd).arg("init").arg(path).exec()); return Ok(HgRepo) } pub fn discover(path: &Path, cwd: &Path) -> CargoResult { - try!(try!(process("hg", cwd)).arg("root").cwd(path).exec_with_output()); + try!(process("hg").cwd(cwd).arg("root").cwd(path).exec_with_output()); return Ok(HgRepo) } } -- 2.30.2